package com.yan.watch;

import java.util.LinkedList;
import java.util.List;

/**
 * 微信公众号
 */
public abstract class AbstractSubject<E extends Observer> implements Subject<E> {
    private List<E> observers = new LinkedList<>();

    @Override
    public void attach(E observer) {
        observers.add(observer);
    }

    @Override
    public void detach(E observer) {
        observers.remove(observer);
    }

    @Override
    public void notify(String message) {
        observers.forEach(observer -> observer.update(message));
    }
}
